const synth = window.speechSynthesis;

export const speak = (text) => {
  if (!synth) return;

  const utterance = new SpeechSynthesisUtterance(text);
  utterance.lang = 'en-US';
  utterance.rate = 0.9;
  
  // 停止当前正在播放的语音
  synth.cancel();
  
  try {
    synth.speak(utterance);
  } catch (error) {
    console.error('语音播放失败:', error);
  }
};